package com.idealighter.game.games.doudizhu.struct;

import com.idealighter.game.games.common.AbstractSeat;
import com.idealighter.game.games.doudizhu.dto.SeatInfo;

import java.util.EnumSet;
import java.util.List;
import java.util.concurrent.ScheduledFuture;

/**
 * 斗地主位置.
 *
 */
public abstract class DouDiZhuSeat extends AbstractSeat {
  // 所属桌子
  public DouDiZhuTable table;
  // 是否准备好游戏(客户端加载资源会请求准备完成)
  public boolean ready = false;
  // 牌数据
  public final EnumSet<DouDiZhuCard> cards = EnumSet.noneOf(DouDiZhuCard.class);
  // 报名顺序
  public final int applyOrder;
  // 头像id
  public final int icon;
  // 叫牌类型
  public CallType callType = null;
  // 是否地主
  public boolean landlord = false;
  // 出牌次数
  public int playNum = 0;
  // 上一次给玩家提示出的牌
  public List<DouDiZhuCard> prePromptCards = null;
  // 上一次给玩家提示出的牌类型
  public DouDiZhuCardsType prePromptCardsType = null;
  // 玩家是否加倍
  public Boolean doubled = null;
  // 排名
  public int rank = 0;
  // 步骤(准备、叫地主、加倍、出牌)定时Future
  public ScheduledFuture<?> stepFuture = null;

  // 系统托管
  public boolean sysHost = false;
  // 积分(默认1000)
  public long cedits = 1000;

  /**
   * 构造函数.
   * 
   * @param order .
   * @param table .
   */
  DouDiZhuSeat(int order, int applyOrder, int icon, DouDiZhuTable table) {
    super(order);
    this.applyOrder = applyOrder;
    this.table = table;
    this.icon = icon;
  }

  /**
   * 创建真实玩家座位 .
   * 
   * @param player 玩家.
   * @param order .
   * @param table .
   * @return
   */
  /*
   * public static DouDiZhuSeat createPlayerSeat(Player player, int applyOrder) { DouDiZhuSeat seat
   * = new DouDiZhuSeat(0, applyOrder, player.getIcon(), null); seat.playerId = player.getId();
   * seat.playerName . = player.getPlayerName(); seat.sex = player.getSex().equals("男")?(byte)0 :
   * (byte)1; seat.robot = false; seat.state = SeatState.SEATED;
   * 
   * return seat; }
   */

  /**
   * 创建机器人座位,机器人的playerId为0 .
   * 
   * @param playerName .
   * @param order .
   * @param table .
   * @return
   */
  /*
   * public . static DouDiZhuSeat createRobotSeat(long playerId, String playerName, int icon, int
   * applyOrder) . { DouDiZhuSeat seat = new DouDiZhuSeat(0, applyOrder, icon, null); seat.playerId
   * = playerId; seat.playerName = playerName; seat.sex = RandCodeUtil.randomBoolean()?(byte)0 :
   * (byte)1; seat.robot = true; seat.state = SeatState.SEATED; seat.ready = true;
   * 
   * return . seat; }
   */

  /**
   * 获取SeatInfo .
   * 
   * @return
   */
  public SeatInfo getSeatInfo() {
    SeatInfo seatInfo = new SeatInfo();
    seatInfo.setOrder(order);
    seatInfo.setPlayerId(playerId);
    seatInfo.setPlayerName(playerName);
    seatInfo.setTableId(table.getId().intValue());
    seatInfo.setRank(rank);
    seatInfo.setIcon(icon);
    seatInfo.setSex(sex);
    seatInfo.setCedits(cedits);
    seatInfo.setOffline(sysHost ? 1 : 0);
    return seatInfo;
  }

  /**
   * 重置座位数据 .
   */
  public void reset() {
    this.ready = false;
    this.prePromptCards = null;
    this.prePromptCardsType = null;
    this.callType = null;
    this.landlord = false;
    this.playNum = 0;
    this.doubled = null;
    this.cards.clear();
  }

  /**
   * 清空座位数据 .
   */
  public void clear() {
    this.playerId = 0;
    this.playerName = null;
    reset();
  }

  @SuppressWarnings("unchecked")
  @Override
  public DouDiZhuTable table() {
    return table;
  }

}
